<!DOCTYPE html>
<html>

<head>
    <title>游记列表</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/travel.css"/>
    <script src="/js/plugins/jrender/jrender.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog/dialog.css">
    <script src="/js/plugins/dialog/dialog.min.js"></script>

    <script>
        $(function () {
            //页面加载完毕之后就发送get请求，获取每月推荐的游记
            $.get("/travels/commends", {type: 2}, function (data) {
                //获取到数据之后就进行渲染
                $("#carouselExampleControls").renderValues({list: data}, {
                    //渲染A标签
                    handle: function (ele, value) {
                        $(ele).attr("href","/travelContent.html?id="+value);
                    }
                });
                setTimeout(function () {
                    $("#travelsCommends > .carousel-item:first").addClass("active");
                }, 50);
                //console.log($("#travelsCommends > .carousel-item:first").length);
                //给第一个div加上active属性
            });

            //==================================
            var currentPage = 1 ;//当前页#travelsCommends > div:first"
            var pages ;//总页数
            var travels ;//用来存储数据的
            //页面加载完之后就发送get请求获取到页面的数据，然后再开始进行渲染
            $.get("/travels",{pageSize:2},function (data) {
                //查询到指定的数据之后就进行渲染
                renderView(data);
                //将总页数赋值到全局变量上面
                pages = data.pages;
                //将对象中的数据集合赋值到全局变量当中
                travels = data.list ;
            });

            //实现分页
            //定义一个屏幕滚动事件
            $(window).scroll(function () {
                //判断屏幕是否滚动到了底部
                if(isEnd()){
                    //到了底部之后再判断是否有下一页
                    if(currentPage<pages){
                        //如果没有到达底部的话，就当前页自增之后，发送get请求，获取第二页的数据
                        currentPage ++ ;
                        $.get("/travels",{currentPage:currentPage,pageSize:2},function (data) {
                            //将返回的数据和第一次的数据合并成一个数组，再去渲染
                            $.merge(travels,data.list);
                            //渲染
                            renderView({list:travels});
                        })
                    }else{
                        //如果滚动到了底部就给个友好的提示，使用dialog这个插件进行有好的提示
                        $(document).dialog({
                            type : 'notice',
                            infoText: "已经到底了，兄地,再滚就穿了",
                            autoClose: 1500,
                            position: 'bottom'  // center: 居中; bottom: 底部
                        });
                    }
                }
            })
            //游记搜索实现
            $("#searchBtn").click(function () {
                var keyword = $(".search input").val();
                //带keyword参数到搜索结果页面进行搜索
                //对古按键子编码
                keyword = escape(keyword);
                location.href="/searchResult.html?type=travel&keyword="+keyword;

            })


            //资讯搜索
            $(".searchBtn").click(function () {
                console.log("hello");
            })
        });

        function isEnd() {
            //判断屏幕滚动是否到达底部
            return $(window).height() + $(window).scrollTop() >=$(document).height();
        }

        function renderView(data) {
            $(".monthcontainer").renderValues(data,{
                handler:function (ele, value) {
                    //ele代表的是该标签，
                    $(ele).attr("href","/travelContent.html?id="+value);
                }
            });
        }
    </script>
</head>

<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col-2">
            <a href="index.html">
                <span><i class="fa fa-chevron-left fa-2x"></i></span>
            </a>
        </div>
        <div class="col-10">
            <div class="input-group-sm search">
                <input class="col-8" placeholder="搜索游记">
                <a id="searchBtn" style="color: #ffffff" class="col-2">搜索</a>
            </div>
        </div>
    </div>
</div>


<div class="container">
    <h6>每月冠军游记</h6>
    <div id="carouselExampleControls" class="carousel slide" data-ride="carousel">
        <div id="travelsCommends" class="carousel-inner" render-loop="list">
            <div class="carousel-item">
                <div class="border commend">
                    <a render-key="list.travelId" render-fun="handle">
                        <img render-src="list.coverUrl" width="100%" height="200px">
                        <h1 render-html="list.title"></h1>
                        <small render-html="list.placeName"></small>
                    </a>
                </div>
            </div>
        </div>

        <a class="carousel-control-prev" href="#carouselExampleControls" role="button" data-slide="prev">
            <span class="carousel-control-prev-icon" aria-hidden="true"></span>
            <span class="sr-only"></span>
        </a>
        <a class="carousel-control-next" href="#carouselExampleControls" role="button" data-slide="next">
            <span class="carousel-control-next-icon" aria-hidden="true"></span>
            <span class="sr-only"></span>
        </a>
    </div>
</div>

<div class="container monthcontainer">
    <h6>全部游记</h6>
    <div id="allTravels" render-loop="list">
        <div class="row detail">
            <div class="col">
                <a href="travelContent.html" render-key="list.id" render-fun="handler">
                    <h4 render-html="list.title"></h4>
                </a>
                <p>
                    <a href="userProfiles.html" >
                        <img class="rounded-circle head-img" render-src="list.author.headImgUrl">
                        <span render-html="list.author.nickName"></span> </a> 在
                    <span class="addr" render-html="list.place.name"></span>

                </p>
                <p>
                    <i class="fa fa-eye fa-fw"></i>
                    <span>1000</span>
                    <i class="fa fa-commenting fa-fw"></i>
                    <span>1000</span>
                </p>
            </div>
            <div class="col bigimg">
                <a href="travelContent.html" render-key="list.id" render-fun="handler" >
                    <img render-src="list.coverUrl">
                </a>
            </div>
        </div>
    </div>
</div>



</body>

</html>